//
// Created by andrew on 2022/3/19.
//


#include <vector>
#include <unordered_map>
#include <iostream>
#include <gtest/gtest.h>

using namespace std;

class Solution {
public:
    static vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int, int> hashTable;
        for (int i = 0;i < nums.size(); i++) {
            auto it = hashTable.find(target - nums[i]);
            if(it != hashTable.end())
                return {it->second, i};
            hashTable[nums[i]] = i;
        }
        return {};
    }
};

using namespace std;



TEST(MapTest1, TwoSum) {
    Solution solution;
    std::vector<int> nums{2, 3, 8, 7};
    int target = 9;

    auto indexs = solution.twoSum(nums, target);

    EXPECT_TRUE(indexs[0] == 0 || indexs[0] == 3);
    EXPECT_TRUE(indexs[1] == 0 || indexs[1] == 3);
}




